package backend.model.admin;

import backend.model.base.DBModel;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;

import javax.persistence.*;

@NamedQueries({ @NamedQuery(name = "findAllShifts", query = "from Shift"),
                @NamedQuery(name = "findAllActiveShifts", query = "from Shift where isActive = true"),
                @NamedQuery(name = "findShiftByName", query = "from Shift where name = :name")
              })
@Entity
@Table(name = "shift")
public class Shift extends DBModel {

	@Id
	@GeneratedValue
	@Column(name = "id")
	private int id;

	@Column(name = "name")
	private String name;

	@Column(name = "description")
	private String description;

	@Column(name = "is_active")
	private boolean isActive;

	@Override
    public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean getIsActive() {
		return isActive;
	}

	public void setIsActive(boolean isActive) {
		this.isActive = isActive;
	}

	@Override
    public String getDisplayLabel() {
		return name;
	}

	@Override
    public int compareTo(Object o) {
		if (!(o instanceof Shift)) {
			return -1;
		} else {
			Shift otherShift = (Shift) o;
			return getDisplayLabel().compareTo(otherShift.getDisplayLabel());
		}
	}
}
